package com.sinosoft.dsp.component.bpm.viewbean.activity.part;

import java.util.ArrayList;
import java.util.List;

import com.sinosoft.dsp.component.bpm.service.core.BpmSelectItemsService;
import com.sinosoft.dsp.component.bpm.viewbean.activity.BpmAbstractActivityPartEditViewBean;
import com.sinosoft.dsp.component.bpm.viewbean.activity.IBpmActivityPartEditViewBean;
import com.sinosoft.dsp.system.core.exception.SinoException;
import com.sinosoft.dsp.system.to.IGenericTO;

public class BpmActivityFormViewBean extends
		BpmAbstractActivityPartEditViewBean implements
		IBpmActivityPartEditViewBean {

	// 表单类别
	public static final String FIELD_FORM_TYPE = "formType";

	// 表单视图配置（表单配置引擎）
	public static final String FIELD_FORM_ID = "formId";

	// 表单视图配置（表单配置引擎）
	public static final String FIELD_FORM_PAGE_URL = "formPageUrl";

	// 表单视图帮助
	public static final String FIELD_FORM_HELP_DOC = "helpDoc";

	// 是否级联删除(boolean)
	public static final String FIELD_FORM_CASCADE = "cascade";

	private List<FormElement> formElements = new ArrayList<FormElement>();

	private FormElement[] selectedRows;

	@Override
	public void init(IGenericTO tos) throws SinoException {
		super.init(tos);

		this.addField(FIELD_FORM_TYPE,
				BpmSelectItemsService.SELECT_ITEM_FORMTYPE_DEFAULT);

		this.addField(FIELD_FORM_CASCADE, false);
	}

	public List<FormElement> getFormElements() {
		return formElements;
	}

	public void setFormElements(List<FormElement> formElements) {
		this.formElements = formElements;
	}

	public void addFormElement() {
		this.formElements.add(new FormElement());
	}
	
	public void removeFormElement() {
		if (selectedRows != null && selectedRows.length > 0) {
			for (FormElement a : selectedRows) {
				this.formElements.remove(a);
			}
		}
	}

	public FormElement[] getSelectedRows() {
		return selectedRows;
	}

	public void setSelectedRows(FormElement[] selectedRows) {
		this.selectedRows = selectedRows;
	}

	/**
	 * 表单元素
	 * 
	 * @author 潘巍（PeterPan）
	 * @since 2011-8-11 下午05:53:44
	 * 
	 */
	public class FormElement {
		// 字段ID
		private String fieldId;

		// 是否显示
		private boolean show = true;

		// 是否编辑
		private boolean edit = true;

		// 是否必填
		private boolean request;

		// 默认值
		private String defaultValue;

		public String getFieldId() {
			return fieldId;
		}

		public void setFieldId(String fieldId) {
			this.fieldId = fieldId;
		}

		public boolean isShow() {
			return show;
		}

		public void setShow(boolean show) {
			this.show = show;
		}

		public boolean isEdit() {
			return edit;
		}

		public void setEdit(boolean edit) {
			this.edit = edit;
		}

		public boolean isRequest() {
			return request;
		}

		public void setRequest(boolean request) {
			this.request = request;
		}

		public String getDefaultValue() {
			return defaultValue;
		}

		public void setDefaultValue(String defaultValue) {
			this.defaultValue = defaultValue;
		}

	}

}
